package com.teamtwoseven.todo;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;


import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TextView;

public class ViewMap extends MapActivity {
	
	private MapView map;
	private long start, stop;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_layout);
        
		long userRowID = Singleton.getInstance().getUserRowID();
		Storage storage = new Storage(ViewMap.this);
		
		Item[] items = storage.getAllItems(userRowID);
                
        map = (MapView) findViewById(R.id.mvMap_View);
        map.setBuiltInZoomControls(true);
        List<Overlay> overlayList = map.getOverlays();
        Drawable drawable = getResources().getDrawable(R.drawable.locationmarker);
        
        GeoPoint point;
		ThisItemizedOverlay customOverlay = new ThisItemizedOverlay(drawable, ViewMap.this);
        for(Item item: items){
        	String locationSearchText = item.getLocation().replaceAll(" ", "%20");
			if (locationSearchText != "No Location") {
				point = NewLocation.getGeoPoint(NewLocation.getLocationInfo(item.getLocation().replaceAll(" ","%20")));
				OverlayItem overlayItem = new OverlayItem(point, "one", "two");
				customOverlay.addOverlayItem(overlayItem);
			}
		}
		overlayList.add(customOverlay);
        
        
    }
    
    

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		//startActivity(new Intent("com.teamtwoseven.todo.MAIN"));
		finish();
	}






	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	/*class Touchy extends Overlay{
		public onTouchEvent(MotionEvent e, MapView m){
			
		}
	}*/


}
